package com.hxd.mall.utils.open

import android.os.Handler
import android.os.Message

object HandlerUtil {
    /**
     * 使用必读：推荐在Activity或者Activity内部持有类中实现该接口，不要使用匿名类，可能会被GC
     */
    class HandlerHolder(listenerWeakReference: OnReceiveMessageListener) : Handler() {
        var mListenerWeakReference = listenerWeakReference // as WeakReference<OnReceiveMessageListener>

        override fun handleMessage(msg: Message) {
//            if (mListenerWeakReference?.get() != null) {
//                mListenerWeakReference?.get()?.handlerMessage(msg)
//            }

            mListenerWeakReference.handlerMessage(msg)
        }
    }

    /**
     * 收到消息回调接口
     */
    interface OnReceiveMessageListener {
        fun handlerMessage(msg: Message)
    }
}